%{
#include "cpnscriptparser.h"
%}

%option noyywrap

B_VALUE     true|false
I_VALUE     [0-9]+
S_VALUE     "[a-zA-Z0-9_]*"
U_VALUE     \(\)

BOOL        bool
INT         int
STRING      string
UNIT        unit

NPLACE      _np
PLACE       _p
NTRANS      _nt
TRANS       _t

ARROW       ->
COLSET      colset
CONN        c:
COMM        ,
DECL        d:
ENUMSEP     \|
HYPH        -
ID          [a-zA-Z][a-zA-Z0-9_]*
LAND        and
LOR         or
LPAREN      \(
LSBRA       \[
MULSEP      `
OEQ         ==
OGT         >
OGTE        >=
OLT         <
OLTE        <=
ONEQ        !=
POP         \+\+
SEP         =
STMTDEL     \n
VAL         val       
VAR         var
VAR_SEP     :
RANGE       \.\.
RPAREN      \)
RSBRA       \]
WITH        with

%%
{B_VALUE}       {yylval.sval = strdup(yytext);
                return B_VALUE_T;}
{I_VALUE}       {yylval.sval = strdup(yytext);
                return I_VALUE_T;}
{S_VALUE}       {yylval.sval = strdup(yytext);
                return S_VALUE_T;}
{U_VALUE}       {yylval.sval = strdup(yytext);
                return U_VALUE_T;}

{BOOL}          {return BOOL_T;}
{INT}           {return INT_T;}
{STRING}        {return STRING_T;}
{UNIT}          {return UNIT_T;}

{NPLACE}        {return NPLACE_T;}
{PLACE}         {return PLACE_T;}
{NTRANS}        {return NTRANS_T;}
{TRANS}         {return TRANS_T;}

{VAL}           {return VAL_T;}
{VAR}           {return VAR_T;}
{WITH}          {return WITH_T;}

{ARROW}         {return ARROW_T;}
{CONN}          {return CONN_T;}
{COMM}          {return COMM_T;}
{COLSET}        {return COLSET_T;}
{DECL}          {return DECL_T;}
{ENUMSEP}       {return ENUMSEP_T;}
{HYPH}          {return HYPH_T;}
{LAND}          {return LAND_T;}
{LOR}           {return LOR_T;}
{LPAREN}        {return LPAREN_T;}
{LSBRA}         {return LSBRA_T;}
{MULSEP}        {return MULSEP_T;}
{OEQ}           {return OEQ_T;}
{OGT}           {return OGT_T;}
{OGTE}          {return OGTE_T;}
{OLT}           {return OLT_T;}
{OLTE}          {return OLTE_T;}
{ONEQ}          {return ONEQ_T;}
{POP}           {return POP_T;}
{SEP}           {return SEP_T;}
{VAR_SEP}       {return VAR_SEP_T;}
{RANGE}         {return RANGE_T;}
{RPAREN}        {return RPAREN_T;}
{RSBRA}         {return RSBRA_T;}

{ID}            {yylval.sval = strdup(yytext);
                return ID_T;}

{STMTDEL}       {AstInfo::i()->handleNewLine();
                return STMTDEL_T;}
<<EOF>>         {static int once = 0;
                return once++ ? 0 : STMTDEL_T;}
[ \t]+          {/*whitespaces*/
                AstInfo::i()->handleColumnShift();}
.               {AstInfo::i()->astHandleLexError(strdup(yytext));
                yylval.sval = strdup(yytext);
                return ERROR_T;}
%%
